package main

import (
	"fmt"
	"strconv"
	"time"
)

func countAndSay(n int) string {
	if n == 1 {
		return "1"
	}
	reString := countAndSay(n - 1)
	slen := len(reString)
	result := ""
	count := 0
	// if slen == 1 {
	// 	return "11"
	// }
	for i := 0; i < slen; i += count {
		count = 1
		for j := i + 1; j < slen; j++ {
			if reString[i] == reString[j] {
				count++
				continue
			} else {
				break
			}
		}
		result = result + strconv.Itoa(count) + string(reString[i])
	}
	return result
}

func main() {
	start := time.Now()
	n := 7
	result := countAndSay(n)
	cost := time.Since(start)
	fmt.Println("result:", result)
	fmt.Println(cost)

}
